<!--打开路由文件复制如下代码 -->
import Vue from 'vue'
import Router from 'vue-router'

import Index from '@/views/index/Index'  //首页
import Home from '@/views/index/Home' //主页
import right from '@/components/UserRight' //右侧
import userlist from '@/views/user/UserList' //用户列表
import usercert from '@/views/user/Certification' //用户审核
import userlook from '@/views/user/UserLook' //用户查看
import usercertlook from '@/views/user/UserCertLook' //用户审核查看


import sellbill from '@/views/ticket/SellBill' //卖票信息
import buybill from '@/views/ticket/BuyBill' //买票信息
import changebill from '@/views/ticket/ChangeBill' //换票信息
import billlist from '@/views/bill/list' //票据列表
import billinfo from '@/views/bill/info' //票据详细
import addbill from '@/views/bill/add' //添加票据

import editsellbill from '@/views/ticket/EditSellBill' //修改卖票信息
import editbuybill from '@/views/ticket/EditBuyBill' //修改买票信息
import editchangebill from '@/views/ticket/EditChangeBill' //修改换票信息
import lookbill from '@/views/ticket/LookBill' //查看详细
import lookbuybill from '@/views/ticket/LookBuyBill' //查看买票详细

import userinfo from '@/views/user/UserInfo' //个人信息
import editpwd from '@/views/user/EditPwd' //修改密码
import webbasic from '@/views/user/WebBasic' //网站基本配置

/* 图片管理 */
import imglist from '@/views/image/ImgList' //图片列表
import addimg from '@/views/image/AddImg' //图片添加
import editimg from '@/views/image/EditImg' //图片编辑


/* 新闻信息 */
import newtype from '@/views/newstype/TypeList' //新闻分类
import addnewstype from '@/views/newstype/AddType' //添加新闻分类
import editnewstype from '@/views/newstype/EditType' //编辑新闻分类

import newlist from '@/views/news/NewsList' //新闻列表
import addnews from '@/views/news/AddNews' //添加新闻
import editnews from '@/views/news/EditNews' //编辑新闻
import looknews from '@/views/news/LookNews' //查看新闻

/* 帮助中心 */
import addhelp from '@/views/help/AddHelp' //添加帮助
import helplist from '@/views/help/HelpList' //帮助列表
import edithelp from '@/views/help/EditHelp' //帮助修改
import lookhelp from '@/views/help/LookHelp' //帮助查看

/* 友情链接*/
import linklist from '@/views/link/LinkList' //友情链接列表
import addlink from '@/views/link/AddLink' //添加友情链接
import editlink from '@/views/link/EidtLink' //编辑友情链接

/* 关于我们 */
import addabout from '@/views/aboutus/AddAbout' //添加关于我们
import aboutlist from '@/views/aboutus/AboutList' //添加关于我们
import lookabout from '@/views/aboutus/LookAbout' //查看关于我们
import editabout from '@/views/aboutus/EditAbout' //编辑关于我们

Vue.use(Router);

<!--
以下就是导航菜单，也就是前面我们看到。下面我解释以下相关参数：
path:路径，默认为："/",
name:标题
compnent:组件，
redirect：跳转页面
menuShow：true or false;控制左侧菜单显示还是隐藏
iconCls：图标样式
children：子模块，这里表示主菜单下面挂载多个子菜单
meta:{requireAuth: true }，主要做登录判断，具体的实现方式在下面的页面路由验证
-->
const routes = [
  {
    path: '/',
    name:'登录',
    component:Index
  },
  {
    path: '/',
    name: 'home',
    component: Home,
    redirect: '/home',
    leaf: true, //只有一个节点
    menuShow: true,
    iconCls: 'iconfont icon-home', //图标样式
    children: [
      {path:'/home', component: right, name: '首页', menuShow: true, meta:{requireAuth: true }}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '用户管理',
    menuShow: true,
    iconCls: 'iconfont icon-users',
    children: [
      {path: '/userlist',     component: userlist,     name: '用户列表',    menuShow: true, meta:{requireAuth: true }},
      {path: '/usercert',     component: usercert,     name: '用户认证审核', menuShow: true, meta:{requireAuth: true }},
      {path: '/userlook',     component: userlook,     name: '查看用户信息', menuShow: false,meta:{requireAuth: true}},
      {path: '/usercertlook', component: usercertlook, name: '用户审核信息', menuShow: false,meta:{requireAuth: true}},
    ]
  },
  {
    path: '/',
    component: Home,
    name: '信息管理',
    menuShow: true,
    iconCls: 'iconfont icon-books',
    children: [

      {path: '/sellbill',             component: sellbill,        name: '卖票信息',    menuShow: true,  meta:{requireAuth: true }},
      {path: '/buybill',              component: buybill,         name: '买票信息',    menuShow: true,  meta:{requireAuth: true }},
      {path: '/changebill',           component: changebill,      name: '换票信息',    menuShow: true,  meta:{requireAuth: true }},
      {path: '/bill/editsellbill',    component: editsellbill,    name: '编辑卖票信息', menuShow: false, meta:{requireAuth: true}},
      {path: '/bill/editbuybill',     component: editbuybill,     name: '编辑买票信息', menuShow: false, meta:{requireAuth: true}},
      {path: '/bill/editchangebill',  component: editchangebill,  name: '编辑换票信息', menuShow: false, meta:{requireAuth: true}},
      {path: '/bill/lookbill',        component: lookbill,        name: '查看票据信息', menuShow: false, meta:{requireAuth: true}},
      {path: '/bill/lookbuybill',     component: lookbuybill,     name: '查看买票信息', menuShow: false, meta:{requireAuth: true}}
    ]
  },
  {
    path: '/bill',
    component: Home,
    name: '票据管理',
    menuShow: true,
    iconCls: 'iconfont icon-books',
    children: [
      {path: '/bill/list',      component: billlist,name: '已开票据列表',  menuShow:  true,    meta:{requireAuth: true }},
      {path: '/bill/info',      component: billinfo,name: '票据详细页',    menuShow:   false,  meta:{requireAuth: true }},
      {path: '/bill/add',       component: addbill, name: '新建开票信息',  menuShow:   true,   meta:{requireAuth: true }},
      {path: '/bill/update',    component: addbill, name: '修改票据信息',  menuShow:   false,  meta:{requireAuth: true }}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '资讯管理',
    menuShow: true,
    iconCls: 'iconfont icon-books2',
    children: [
      {path: '/newtype/newtype',      component: newtype,      name: '资讯分类',     menuShow: true,  meta:{requireAuth: true}},
      {path: '/newtype/addnewstype',  component: addnewstype,  name: '添加资讯分类',  menuShow: false, meta:{requireAuth: true}},
      {path: '/newtype/editnewstype', component: editnewstype, name: '编辑资讯分类',  menuShow: false, meta:{requireAuth: true}},
      {path: '/new/newlist',          component: newlist,      name: '资讯列表',     menuShow: true,  meta:{requireAuth: true}},
      {path: '/new/addnews',          component: addnews,      name: '添加新闻',     menuShow: false, meta:{requireAuth: true}},
      {path: '/new/editnews',         component: editnews,     name: '编辑新闻',     menuShow: false, meta:{requireAuth: true}},
      {path: '/new/looknews',         component: looknews,     name: '查看新闻',     menuShow: false, meta:{requireAuth: true}}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '关于我们',
    menuShow: true,
    iconCls: 'iconfont icon-books1',
    children: [
      {path: '/aboutus/addabout',   component: addabout,    name: '添加关于我们',  menuShow: true,    meta:{requireAuth: true}},
      {path: '/aboutus/aboutlist',  component: aboutlist,   name: '关于我们',     menuShow: true,    meta:{requireAuth: true}},
      {path: '/aboutus/lookabout',  component: lookabout,   name: '查看关于我们',  menuShow: false,   meta:{requireAuth: true}},
      {path: '/aboutus/editabout',  component: editabout,   name: '编辑关于我们',  menuShow: false,   meta:{requireAuth: true}}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '帮助管理',
    menuShow: true,
    iconCls: 'iconfont icon-books2',
    children: [
      {path: '/help/addhelp',     component: addhelp,      name: '添加帮助',     menuShow: true,   meta:{requireAuth: true}},
      {path: '/help/helplist',    component: helplist,     name: '帮助中心',     menuShow: true,   meta:{requireAuth: true}},
      {path: '/help/edithelp',    component: edithelp,     name: '编辑帮助信息',  menuShow: false,  meta:{requireAuth: true}},
      {path: '/help/lookhelp',    component: lookhelp,     name: '查看帮助信息',  menuShow: false,  meta:{requireAuth: true}}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '图片管理',
    menuShow: true,
    iconCls: 'iconfont icon-setting1',
    children: [
      {path: '/img/addimg',   component: addimg,   name: '添加图片', menuShow: true,  meta:{requireAuth: true }},
      {path: '/img/imglist',  component: imglist,  name: '图片管理', menuShow: true,  meta:{requireAuth: true }},
      {path: '/img/editimg',  component: editimg,  name: '编辑图片', menuShow: false, meta:{requireAuth: true }}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '友情链接',
    menuShow: true,
    iconCls: 'iconfont icon-setting1',
    children: [
      {path: '/link/addlink',   component: addlink,   name: '添加友情链接', menuShow: true,  meta:{requireAuth: true }},
      {path: '/link/linklist',  component: linklist,  name: '友情链接管理', menuShow: true,  meta:{requireAuth: true }},
      {path: '/link/editlink',  component: editlink,  name: '编辑友情链接', menuShow: false, meta:{requireAuth: true }}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '系统设置',
    menuShow: true,
    iconCls: 'iconfont icon-setting1',
    children: [
      {path: '/userinfo', component: userinfo, name: '个人信息', menuShow: true,   meta:{requireAuth: true }},
      {path: '/editpwd',  component: editpwd,  name: '修改密码', menuShow: true,   meta:{requireAuth: true }},
      {path: '/webbasic',  component: webbasic,  name: '基本配置', menuShow: true, meta:{requireAuth: true }},
    ]
  }
];

const router = new Router({
  routes
});

<!--这个是请求页面路由的时候会验证token存不存在，不存在的话会到登录页
这段代码大家可以根据自己的需求来写，不一定按照我 写的。
-->
router.beforeEach((to, from, next) => {
  if(to.meta.requireAuth) {
    fetch('m/is/login').then(res => {
      if(res.errCode == 200) {
        next();
      } else {
        if(getCookie('session')) {
          delCookie('session');
        }
        if(getCookie('u_uuid')) {
          delCookie('u_uuid');
        }
        next({
          path: '/'
        });
      }
    });
  } else {
    next();
  }
});
export default router;
